<!-- 医护, 查看某个会员的全部健康档案记录 -->
<template>
	<view>
		<!-- <cu-custom bgColor="bg-E96141" 
			:isUseMyBack="true" 
			:goBackMainMenu="'doctorNurse'"
			:backRouterName="'doctorNurse'">
			<block slot="backText">返回</block>
			<block slot="content">会员健康档案代管</block>
		</cu-custom> -->
		<my-nav 
			:isBack="true"
			:goBackMainMenu="'doctorNurse'"
			:bgColor="'project-theme-bg'">
			<block slot="backText">返回</block>
			<block slot="content">会员健康档案代管</block>
		</my-nav>
		
		<!-- 会员信息 -->
		<view class="member-info" :style="{position:headerPosition}">
			<view class="list-item">
				<text class="pure-text">
					会员姓名：{{memberInfo.realname}}{{memberInfo.sex=='1'?' [男]':''}}{{memberInfo.sex=='2'?' [女]':''}}
				</text>
			</view>
			<view class="list-item">
				<!-- <button class="cu-btn bg-cyan round sm btn-1" @tap="reloadData()">
					<text class="title">刷新页面</text>
				</button> -->
				<button class="cu-btn bg-cyan round sm btn-1" @tap="toYiHuPage()">
					<text class="title">回到医护</text>
				</button>
			</view>
			<view class="list-item">
				<text class="pure-text">
					会员账号：{{memberInfo.phone}}
				</text>
			</view>
			<view class="list-item">
				<button class="cu-btn bg-cyan round sm btn-2" @tap="addData()">
					<text class="title">新增档案</text>
				</button>
			</view>
		</view>
		
		<!-- 分页数据 -->
		<view class="no-data-con"
			v-if="!pageDataList || pageDataList.length==0">
			<image src="https://ylb123.oss-cn-hangzhou.aliyuncs.com/app/empty.png"></image>
			<view class="title">该会员还没有健康档案~</view>
		</view>
		<view class="page-list-con">
			<view
				v-for="(item, index) in pageDataList" :key="item.id"
				class="one-row">
				<view class="left-con">
					<view class="day-con">{{item.day}}</view>
					<view class="year-month-con">{{item.yearMonth}}</view>
					<view class="opers">
						<button class="cu-btn bg-cyan round sm btn-1" @tap="editData(item)">
							<text class="title">档案详情</text>
						</button>
					</view>
				</view>
				<view class="right-con">
					<view class="title">
						<text class="account">
							[医生] {{item.doctor?item.doctor:'无'}}
						</text>
						<text class="name">
							[护士] {{item.nurse?item.nurse:'无'}}
						</text>
					</view>
					<view class="list-value">
						血压：{{item.xueya?(item.xueya + ' mmHg'):'暂无记录'}} 
					</view>
					<view class="list-value">
						血糖：{{item.xuetang?(item.xuetang + ' mmol/L'):'暂无记录'}} 
					</view>
					<view class="list-value">
						血脂：{{item.xuezhi?(item.xuezhi + ' mmol/L'):'暂无记录'}}
					</view>
					<view class="list-value">
						尿酸：{{item.niaosuan?(item.niaosuan + ' μmol/L'):'暂无记录'}} 
					</view>
				</view>
			</view>
		</view>
		<uni-load-more 
			v-if="pageDataList && pageDataList.length>0"
			:status="loadingType"></uni-load-more>
	</view>
</template>

<script>
	import {
		USER_HAS_LOGIN,
	} from "@/common/util/constants"
	import uniLoadMore from '@/components/uni-load-more/uni-load-more.vue';
	import myNav from '@/components/my-componets/my-nav.vue';
	import moment from 'moment'
	
	export default {
		name: "dnSingleMemberSee",
		components: {
			uniLoadMore,
			myNav,
		},
		props:{
			pageCur: String,
		},
		data() {
			return {
				headerPosition:"fixed",
				memberInfo: {
					id: '',
					phone: '',
					realname: '',
					sex: '',
					birthday: '',
					address: '',
				},
				
				loadingType: 'more', //加载更多状态
				filterIndex: 0, 
				pageDataList: [],
				
				currPageNo: 1,
				totalPageNo: 1,
				pageSize: 20,
			}
		},
		created() {
			//console.log('see created')
			this.loadData();
		},
		onLoad: function (option) {
			//console.log('see onLoad option = ', option)
			this.memberInfo.id = option.memId?option.memId:''
			this.memberInfo.phone = option.memPhone?option.memPhone:''
			this.memberInfo.realname = option.memRealname?option.memRealname:''
			this.memberInfo.sex = option.memSex?option.memSex:''
			this.memberInfo.birthday = option.memBirthday?option.memBirthday:''
			this.memberInfo.address = option.memAddress?option.memAddress:''
		},
		methods: {
			//重新加载(暂不使用)
			reloadData(){
				this.currPageNo = 1
				this.totalPageNo = 1
				this.pageSize = 20
				this.pageDataList = []
				this.loadData();
			},
			//回到医护页面
			toYiHuPage(){
				uni.redirectTo({
					url: '/pages/index/index?pageCur=doctorNurse'
				})
			},
			//代该会员-添加健康档案
			addData(){
				let _params = '?nouse=1' + 
					'&memId=' + this.memberInfo.id + 
					'&memPhone=' + this.memberInfo.phone + 
					'&memRealname=' + this.memberInfo.realname + 
					'&memSex=' + this.memberInfo.sex + 
					'&memBirthday=' + this.memberInfo.birthday + 
					'&memAddress=' + this.memberInfo.address + 
					'&jkdaId='
				//redirectTo 不会压栈
				//navigateTo 会压栈
				uni.navigateTo({
					url: '/pages/member-health-record/dn-single-member-save' + _params
				})
			},
			//代该会员-编辑健康档案
			editData(jkdaItem){
				if(!jkdaItem || !jkdaItem.id){
					this.$tip.toast('数据错误')
					return false
				}
				let _params = '?nouse=1' + 
					'&memId=' + this.memberInfo.id + 
					'&memPhone=' + this.memberInfo.phone + 
					'&memRealname=' + this.memberInfo.realname + 
					'&memSex=' + this.memberInfo.sex + 
					'&memBirthday=' + this.memberInfo.birthday + 
					'&memAddress=' + this.memberInfo.address + 
					'&jkdaId=' + jkdaItem.id
				uni.navigateTo({
					url: '/pages/member-health-record/dn-single-member-save' + _params
				})
			},
			onPageScroll(e){
				//兼容iOS端下拉时顶部漂移
				if(e.scrollTop>=0){
					this.headerPosition = "fixed";
				}else{
					this.headerPosition = "absolute";
				}
			},
			//下拉刷新
			onPullDownRefresh(){
				this.loadData('refresh');
			},
			//加载更多
			onReachBottom(){
				this.loadData();
			},
			//加载分页数据 ，带下拉刷新和上滑加载
			async loadData(type='add', loading) {
				let that = this
				//没有更多直接返回
				if(type === 'add'){
					if(that.loadingType === 'nomore'){
						return;
					}
					that.loadingType = 'loading';
				}else if(type === 'refresh'){
					that.pageDataList = []
					that.currPageNo = 1
				}else{
					that.loadingType = 'more'
				}
				if(that.currPageNo>that.totalPageNo){
					that.loadingType = 'nomore'
					if(loading == 1){
						uni.hideLoading()
					}else{
						uni.stopPullDownRefresh();
					}
					return false
				}
				
				let _pageParams = {
					pageNo: that.currPageNo,
					pageSize: that.pageSize,
					uid: this.memberInfo.id
				}
				uni.showLoading({
					title: '加载中...',
					mask: true,
				})
				let list = await that.$http.get('/health/jkda/listByUid', {params:_pageParams})
					.then(res => {
						if(res.data.success){
							uni.hideLoading()
							let jsonData = res.data.result
							if(!jsonData){
								return []
							}
							that.totalPageNo = jsonData.pages
							let _list = jsonData.records?jsonData.records:[]
							if(_list && _list.length>0){
								let _item = {}
								for(let i=0;i<_list.length;i++){
									_item = _list[i]
									_item.createTimeShort = moment(_item.createTime).format('YYYY-M-D')
									_item.day = moment(_item.createTime).format('D')
									_item.yearMonth = moment(_item.createTime).format('YYYY年M月')
								}
							}
							return _list
						}else{
							uni.hideLoading()
						}
					}).catch(err => {
						uni.hideLoading()
						return []
					});
				
				if(list && list.length>0){
					list.forEach(item=>{
						that.pageDataList.push(item)
					})
				}
				
				//判断是否还有下一页，有是more  没有是nomore
				that.loadingType  = (that.currPageNo >= that.totalPageNo)?'nomore':'more'
				if(type === 'refresh'){
					if(loading == 1){
						uni.hideLoading()
					}else{
						uni.stopPullDownRefresh();
					}
				}
				
				if(that.currPageNo<that.totalPageNo){
					that.currPageNo++
				}
			},
			stopPrevent(){
			},
		}
	}
</script>

<style lang="scss" scoped>
	
	/* 会员信息 */
	.member-info{
		width: 100%;
		position: fixed;
		z-index: 10;
		left: 0;
		// #ifdef APP-PLUS
		top: 78px;
		// #endif
		background-color: #ffffff;
		height: 100px;
		overflow: hidden;
		padding: 20px;
		border: 0px solid #f00;
		box-shadow: 0 1px 5px rgba(0, 0, 0, 0.06);
		.list-item{
			float:left;
			width: 50%;
			margin-bottom: 10px;
			.pure-text{
				height: 30px;
				line-height: 30px;
			}
			.btn-1{
				float: right;
				background-color: #1CBBB4;
				height: 30px;
				line-height: 30px;
			}
			.btn-2{
				float: right;
				background-color: #ff9800;
				height: 30px;
				line-height: 30px;
			}
		}
	}
	
	/* 分页列表 */
	.no-data-con{
		text-align: center;
		padding: 40% 0 0 0;
		image{
			width: 150px !important;
			height: 150px !important;
		}
		.title{
			color: #aaaaaa;
		}
	}
	.page-list-con{
		margin-top: 100px;
		padding: 20upx;
		color: #999999;
		.one-row{
			width: 100%;
			height: 260upx;
			overflow: hidden;
			background-color: #FFFFFF;
			margin-bottom: 20upx;
			padding: 20upx;
			border-radius: 10upx;
			border: 1px solid #ececec;
			.left-con{
				width: 30%;
				float: left;
				text-align: center;
				border-right: 1px dashed #cccccc;
				.day-con{
					font-size: 80upx;
					font-weight: bold;
				}
				.year-month-con{
					font-size: 32upx;
					margin-bottom: 10upx;
				}
				.opers{
					font-size: 48upx;
					text{
						font-size: 24upx;
					}
					.btn-1{
						width: 85%;
						background-color: #ff9270;
						height: 56upx;
						line-height: 56upx;
						margin-bottom: 10upx;
					}
				}
			}
			.right-con{
				width: 68%;
				float: right;
				border: 0px solid #f00;
				height: 220upx;
				overflow: hidden;
				.title{
					font-size: 26upx;
					font-weight: bold;
					margin-bottom: 10upx;
					height: 50upx;
					line-height: 50upx;
					.account{
						margin-right: 10upx;
						color: #1CBBB4;
					}
					.name{
						float: right;
						color: #EA6040;
					}
				}
				.list-value{
					margin-bottom: 5upx;
				}
			}
		}
		
	}
	

</style>
